<?php

    class itManagerTest extends itTestCase {
        
        /**
         * @test
         */
        public function testGeneral() {
            $manager = itManager::getInstance();
            $this->assertNotNull($manager);
            $i = new itRulesIntelligencer('Name');
            $manager->setIntelligencer($i);
            $this->assertTrue($manager->hasIntelligencer($i));
            $this->assertTrue($manager->hasIntelligencerByName('Name'));
            $this->assertEquals($i, $manager->getIntelligencerByName('Name'));
            $manager->delIntelligencer($i);
            $this->assertFalse($manager->hasIntelligencerByName('Name'));
            $manager->addIntelligencer($i, 1);
            $this->assertTrue($manager->hasIntelligencer($i));
            try {
                $manager->addIntelligencer($i, 1);
                $this->fail();
            } catch(itException $e) {
                $this->assertType('itParameterException', $e);
            }
            $manager->clear();
            $this->assertFalse($manager->hasIntelligencer($i));
        }
        
        public function testNullPriorities() {
            $i1 = $this->getMock('itRulesIntelligencer');
            $i2 = $this->getMock('itRulesIntelligencer');
            $i1->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i1->expects($this->once())->method('load')->will($this->returnValue(true)); // first
            $i2->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i2->expects($this->never())->method('load');
            $manager = new itManager();
            $manager->setIntelligencer($i1)->setIntelligencer($i2);
            $this->assertTrue($manager->load('AAA'));
            $manager->clear();    
        }
        
        public function testFirstNullPriority() {
            $i1 = $this->getMock('itRulesIntelligencer');
            $i2 = $this->getMock('itRulesIntelligencer');
            $i1->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i1->expects($this->never())->method('load')->will($this->returnValue(true)); // first
            $i2->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i2->expects($this->once())->method('load')->will($this->returnValue(true));
            $manager = new itManager();
            $manager->setIntelligencer($i1)->setIntelligencer($i2, 10);
            $this->assertTrue($manager->load('AAA'));
            $manager->clear();
        }
        
        public function testTwoNotNullPriorities() {
            $i1 = $this->getMock('itRulesIntelligencer');
            $i2 = $this->getMock('itRulesIntelligencer');
            $i1->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i1->expects($this->never())->method('load')->will($this->returnValue(true)); // first
            $i2->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i2->expects($this->once())->method('load')->will($this->returnValue(true));
            $manager = new itManager();
            $manager->setIntelligencer($i1, 12)->setIntelligencer($i2, 10);
            $this->assertTrue($manager->load('AAA'));
            $manager->clear();
        }
        
        public function testControlNone() {
            $i1 = $this->getMock('itRulesIntelligencer');
            $i2 = $this->getMock('itRulesIntelligencer');
            $i1->expects($this->any())->method('inControl')->will($this->returnValue(false));
            $i1->expects($this->never())->method('load');
            $i2->expects($this->any())->method('inControl')->will($this->returnValue(false));
            $i2->expects($this->never())->method('load');
            $manager = new itManager();
            $manager->setIntelligencer($i1)->setIntelligencer($i2);
            $this->assertFalse($manager->load('AAA'));
            $manager->clear();
        }
        
        public function testControlOne() {
            $i1 = $this->getMock('itRulesIntelligencer');
            $i2 = $this->getMock('itRulesIntelligencer');
            $i1->expects($this->any())->method('inControl')->will($this->returnValue(false));
            $i1->expects($this->never())->method('load');
            $i2->expects($this->any())->method('inControl')->will($this->returnValue(true));
            $i2->expects($this->once())->method('load')->will($this->returnValue(true));
            $manager = new itManager();
            $manager->setIntelligencer($i1)->setIntelligencer($i2);
            $this->assertTrue($manager->load('AAA'));
            $manager->clear();
        }
        
        /* this is used to check the logger
        public function testLogger() {
            require_once 'Log.php';
            Manager::getInstance()
               ->setLogger(new PearLogger(
                   \Log::singleton('file', TEST_DATA.'/Individual/Manager/Logger/log.txt')))
                ->clear()
                ->addAndCreate(new RulesIntelligencer())
                ->setRulesAndCreate(new ClassRules())
                    ->addClass('Manager_Logger_A', TEST_DATA.'/Individual/Manager/Logger/Manager_Logger_A.php')
                    ->getIntelligencer()
                ->control();
                
           new \Manager_Logger_A();
        } */
    }
    
?>